﻿using Kinlo.Entitys;
using LiveChartsCore.Defaults;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using UIWindows.Models.Homes;
using UIWindows.Tools.Helper;
using UIWindows.UserControls;
using XingLucifer.IBase.Enums;

namespace UIWindows.GlobalStatics
{
    [Attributes.Singleton]
    public class HomeStatic
    {
        public ObservableCollection<TrendModel> Trend { get; set; }
        public EquipmentTimeModel EquipmentTime { get; set; }
        public AsyncObservableCollection<MessageBeforeScanCodeModel> Battery_BeforeScanCode { get; set; }

        /// <summary>
        /// 卷芯上料扫码信息输出
        /// </summary>
        public AsyncObservableCollection<CoilCoreLoadingDataScanCodeModel> CoilCoreLoadingDataScanCode { get; set; }

        /// <summary>
        /// 装盘机扫码信息输出 和卷芯上料扫码信息用同一个就完事了
        /// </summary>
        //public AsyncObservableCollection<CoilCoreLoadingDataScanCodeModel> TrayFillerDataDataScanCode { get; set; }


        public AsyncObservableCollection<MessageShortCircuitModel> Battery_ShortCircuit { get; set; }
        public AsyncObservableCollection<MessageBeforeWeighingModel> Battery_BeforeWeighing { get; set; }
        public AsyncObservableCollection<Kinlo.Entitys.ProductionData> Battery_AfterFluidInjection { get; set; }

        /// <summary>
        /// 换套杯数据
        /// </summary>
        public AsyncObservableCollection<Kinlo.Entitys.CupSleeveChangingData> Battery_CupSleeveChangingData { get; set; }
        /// <summary>
        /// 折极耳数据
        /// </summary>
        public AsyncObservableCollection<Kinlo.Entitys.PoleEarFoldingData> Battery_PoleEarFoldingData { get; set; }


        /// <summary>
        /// 入壳机数据
        /// </summary>
        public AsyncObservableCollection<Kinlo.Entitys.ShellInsertionData> Battery_ShellInsertionData { get; set; }
        /// <summary>
        /// 点底焊数据
        /// </summary>
        public AsyncObservableCollection<Kinlo.Entitys.SpotoWeldData> Battery_SpotoWeldData { get; set; }
        /// <summary>
        /// 辊槽机数据
        /// </summary>
        public AsyncObservableCollection<Kinlo.Entitys.GrooveRollingMachineData> Battery_GrooveRollingMachineData { get; set; }
        /// <summary>
        /// 短路测试仪数据
        /// </summary>
        public AsyncObservableCollection<Kinlo.Entitys.ShortCircuitTesterData> Battery_ShortCircuitTesterData { get; set; }
        /// <summary>
        /// 装盘机
        /// </summary>
        public AsyncObservableCollection<Kinlo.Entitys.TrayFillerData> Battery_TrayFillerData { get; set; }
        /// <summary>
        /// 拆盘机
        /// </summary>
        public AsyncObservableCollection<Kinlo.Entitys.DismantlingDiscData> Battery_DismantlingDiscData { get; set; }
        /// <summary>
        /// 盖帽焊
        /// </summary>
        public AsyncObservableCollection<Kinlo.Entitys.CapWeldingData> Battery_CapWeldingData { get; set; }
        /// <summary>
        /// 封口机
        /// </summary>
        public AsyncObservableCollection<Kinlo.Entitys.SealingMachineData> Battery_SealingMachineData { get; set; }

        /// <summary>
        /// 预充装盘行扫码输出信息
        /// </summary>
        public AsyncObservableCollection<Kinlo.Entitys.Plate> Battery_PlateData { get; set; }
        /// <summary>
        /// 清洗机
        /// </summary>
        public AsyncObservableCollection<Kinlo.Entitys.CleaningData> Battery_CleaningData { get; set; }
        /// <summary>
        /// 套膜机
        /// </summary>
        public AsyncObservableCollection<Kinlo.Entitys.MantleData> Battery_MantleData { get; set; }
        /// <summary>
        /// 喷码机
        /// </summary>
        public AsyncObservableCollection<Kinlo.Entitys.MarkingData> Battery_MarkingData { get; set; }

        public ChartDataModel ChartData { get; set; }
        public HomeStatic()
        {
            try
            {
                if (System.IO.File.Exists(GlobalStatic.EquipmentTimePath))
                {
                    EquipmentTime = System.Text.Json.JsonSerializer.Deserialize<EquipmentTimeModel>(System.IO.File.ReadAllText(GlobalStatic.EquipmentTimePath, Encoding.UTF8), GlobalStatic.Options);
                }
                else
                {
                    EquipmentTime = new EquipmentTimeModel();
                }
            }
            catch (Exception)
            {
                EquipmentTime = new EquipmentTimeModel();
            }
            Trend = new ObservableCollection<TrendModel>();
            try
            {
                if (System.IO.File.Exists(GlobalStatic.ChartDataPath))
                {
                    ChartData = System.Text.Json.JsonSerializer.Deserialize<ChartDataModel>(System.IO.File.ReadAllText(GlobalStatic.ChartDataPath, Encoding.UTF8), GlobalStatic.Options);
                }
                else
                {
                    ChartData = new ChartDataModel();
                }
            }
            catch (Exception)
            {
                ChartData = new ChartDataModel();
            }
            ChartData.OV_AfterWeighingPassingRate = new ObservableValue();
            ChartData.OV_LessLiquid = new ObservableValue();
            ChartData.OV_MultiLiquid = new ObservableValue();
            ChartData.OV_LiquidInjection_PassingRate = new ObservableValue();

            ChartData.OV_AfterWeighingPassingRate.Value = ChartData.AfterWeighingPassingRate;
            ChartData.OV_LessLiquid.Value = ChartData.NG_LessLiquid;
            ChartData.OV_MultiLiquid.Value = ChartData.NG_MultiLiquid;
            ChartData.OV_LiquidInjection_PassingRate.Value = ChartData.LiquidInjection_PassingRate;

            Battery_BeforeScanCode = new AsyncObservableCollection<MessageBeforeScanCodeModel>();
            CoilCoreLoadingDataScanCode = new AsyncObservableCollection<CoilCoreLoadingDataScanCodeModel>();

            //TrayFillerDataDataScanCode = new AsyncObservableCollection<CoilCoreLoadingDataScanCodeModel>();

            Battery_ShortCircuit = new AsyncObservableCollection<MessageShortCircuitModel>();
            Battery_BeforeWeighing = new AsyncObservableCollection<MessageBeforeWeighingModel>();
            Battery_AfterFluidInjection = new AsyncObservableCollection<Kinlo.Entitys.ProductionData>();

            Battery_CupSleeveChangingData = new AsyncObservableCollection<Kinlo.Entitys.CupSleeveChangingData>();
            Battery_PoleEarFoldingData = new AsyncObservableCollection<Kinlo.Entitys.PoleEarFoldingData>();

            Battery_ShellInsertionData = new AsyncObservableCollection<Kinlo.Entitys.ShellInsertionData>();
            Battery_SpotoWeldData = new AsyncObservableCollection<Kinlo.Entitys.SpotoWeldData>();
            Battery_GrooveRollingMachineData = new AsyncObservableCollection<Kinlo.Entitys.GrooveRollingMachineData>();
            Battery_ShortCircuitTesterData = new AsyncObservableCollection<Kinlo.Entitys.ShortCircuitTesterData>();
            Battery_TrayFillerData = new AsyncObservableCollection<Kinlo.Entitys.TrayFillerData>();

            Battery_DismantlingDiscData = new AsyncObservableCollection<Kinlo.Entitys.DismantlingDiscData>();
            Battery_CapWeldingData = new AsyncObservableCollection<Kinlo.Entitys.CapWeldingData>();
            Battery_SealingMachineData = new AsyncObservableCollection<Kinlo.Entitys.SealingMachineData>();




             Battery_PlateData = new AsyncObservableCollection<Kinlo.Entitys.Plate>();

            Battery_CleaningData = new AsyncObservableCollection<Kinlo.Entitys.CleaningData>();
            Battery_MantleData = new AsyncObservableCollection<Kinlo.Entitys.MantleData>();
            Battery_MarkingData = new AsyncObservableCollection<Kinlo.Entitys.MarkingData>();

           
    }

        public void SaveEquipmentTime() => System.IO.File.WriteAllText(GlobalStatic.EquipmentTimePath, System.Text.Json.JsonSerializer.Serialize(EquipmentTime, GlobalStatic.Options), Encoding.UTF8);
        public void SaveChartData() => System.IO.File.WriteAllText(GlobalStatic.ChartDataPath, System.Text.Json.JsonSerializer.Serialize(ChartData, GlobalStatic.Options), Encoding.UTF8);

        /// <summary>
        /// 前扫码信息输出
        /// </summary>
        /// <param name="barcode">条码</param>
        /// <param name="message">结果</param>
        /// <param name="dateTime">时间</param>
        public void AddInBattery(string barcode, ResultTypes message, DateTime dateTime, int location)
        {
            for (int i = 0; i < 3; i++)
            {
                try
                {
                    Battery_BeforeScanCode.Insert(0, new MessageBeforeScanCodeModel()
                    {
                        BarCode = barcode,
                        Location = location,
                        Result = message,
                        Time = dateTime.ToString("yyyy/MM/dd HH:mm:ss")
                    });
                    if (Battery_BeforeScanCode.Count > 400)
                    {
                        Battery_BeforeScanCode.RemoveAt(399);
                    }
                    return;
                }
                catch (Exception ex)
                {
                    $"前扫码 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                }
            }
        }
        /// <summary>
        /// 卷芯上料扫码信息输出
        /// </summary>
        /// <param name="barcode"></param>
        /// <param name="dateTime"></param>
        /// <param name="location"></param>
        public void AddInCoilCoreLoadingDataBattery(string barcode, DateTime dateTime, ScanPositionType location,int number=256)
        {
            for (int i = 0; i < 3; i++)
            {
                try
                {
                    CoilCoreLoadingDataScanCode.Insert(0, new CoilCoreLoadingDataScanCodeModel()
                    {
                        PalletNo = barcode,
                        Position = location.ToString(),
                        AcquisitionTime = dateTime.ToString("yyyy/MM/dd HH:mm:ss"),
                        Number= number
                    });
                    if (CoilCoreLoadingDataScanCode.Count > 400)
                    {
                        CoilCoreLoadingDataScanCode.RemoveAt(399);
                    }
                    return;
                }
                catch (Exception ex)
                {
                    $"卷芯上料扫码 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                }
            }
        }
        
        ///// <summary>
        ///// 装盘机扫码信息输出
        ///// </summary>
        ///// <param name="barcode"></param>
        ///// <param name="dateTime"></param>
        ///// <param name="location"></param>
        //public void AddInCoilCoreLoadingDataBattery(string barcode, DateTime dateTime, ScanPositionType location, int number = 256)
        //{
        //    for (int i = 0; i < 3; i++)
        //    {
        //        try
        //        {
        //            TrayFillerDataDataScanCode.Insert(0, new CoilCoreLoadingDataScanCodeModel()
        //            {
        //                PalletNo = barcode,
        //                Position = location.ToString(),
        //                AcquisitionTime = dateTime.ToString("yyyy/MM/dd HH:mm:ss")
        //            });
        //            if (CoilCoreLoadingDataScanCode.Count > 400)
        //            {
        //                CoilCoreLoadingDataScanCode.RemoveAt(399);
        //            }
        //            return;
        //        }
        //        catch (Exception ex)
        //        {
        //            $"卷芯上料扫码 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
        //        }
        //    }
        //}

        public void AddBatteryTest(object data, MachineInfoTypes machineInfoTypes)
        {
            switch(machineInfoTypes)
            {
                case MachineInfoTypes.换套杯:
                    {
                        var entityData = data as CupSleeveChangingData;
                        for (int i = 0; i < 3; i++)
                        {
                            try
                            {
                                Battery_CupSleeveChangingData.Insert(0, entityData);
                                if (Battery_CupSleeveChangingData.Count > 400)
                                {
                                    Battery_CupSleeveChangingData.RemoveAt(399);
                                }
                                return;
                            }
                            catch (Exception ex)
                            {
                                $"{machineInfoTypes.ToString()} 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                            }
                        }
                        break;
                    }
                case MachineInfoTypes.折极耳:
                    {
                        var entityData = data as PoleEarFoldingData;
                        for (int i = 0; i < 3; i++)
                        {
                            try
                            {
                                Battery_PoleEarFoldingData.Insert(0, entityData);
                                if (Battery_PoleEarFoldingData.Count > 400)
                                {
                                    Battery_PoleEarFoldingData.RemoveAt(399);
                                }
                                return;
                            }
                            catch (Exception ex)
                            {
                                $"{machineInfoTypes.ToString()} 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                            }
                        }
                        break;
                    }
                case MachineInfoTypes.入壳机:
                    {
                        var entityData = data as ShellInsertionData;
                        for (int i = 0; i < 3; i++)
                        {
                            try
                            {
                                Battery_ShellInsertionData.Insert(0, entityData);
                                if (Battery_ShellInsertionData.Count > 400)
                                {
                                    Battery_ShellInsertionData.RemoveAt(399);
                                }
                                return;
                            }
                            catch (Exception ex)
                            {
                                $"{machineInfoTypes.ToString()} 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                            }
                        }
                        break;
                    }
                case MachineInfoTypes.点底焊:
                    {
                        var entityData = data as SpotoWeldData;
                        for (int i = 0; i < 3; i++)
                        {
                            try
                            {
                                Battery_SpotoWeldData.Insert(0, entityData);
                                if (Battery_SpotoWeldData.Count > 400)
                                {
                                    Battery_SpotoWeldData.RemoveAt(399);
                                }
                                return;
                            }
                            catch (Exception ex)
                            {
                                $"{machineInfoTypes.ToString()} 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                            }
                        }
                        break;
                    }
                case MachineInfoTypes.辊槽机:
                    {
                        var entityData = data as GrooveRollingMachineData;
                        for (int i = 0; i < 3; i++)
                        {
                            try
                            {
                                Battery_GrooveRollingMachineData.Insert(0, entityData);
                                if (Battery_GrooveRollingMachineData.Count > 400)
                                {
                                    Battery_GrooveRollingMachineData.RemoveAt(399);
                                }
                                return;
                            }
                            catch (Exception ex)
                            {
                                $"{machineInfoTypes.ToString()} 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                            }
                        }
                        break;
                    }
                case MachineInfoTypes.短路测试仪:
                    {
                        var entityData = data as ShortCircuitTesterData;
                        for (int i = 0; i < 3; i++)
                        {
                            try
                            {
                                Battery_ShortCircuitTesterData.Insert(0, entityData);
                                if (Battery_ShortCircuitTesterData.Count > 400)
                                {
                                    Battery_ShortCircuitTesterData.RemoveAt(399);
                                }
                                return;
                            }
                            catch (Exception ex)
                            {
                                $"{machineInfoTypes.ToString()} 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                            }
                        }
                        break;
                    }
                case MachineInfoTypes.装盘机:
                    {
                        var entityData = data as TrayFillerData;
                        for (int i = 0; i < 3; i++)
                        {
                            try
                            {
                                Battery_TrayFillerData.Insert(0, entityData);
                                if (Battery_TrayFillerData.Count > 400)
                                {
                                    Battery_TrayFillerData.RemoveAt(399);
                                }
                                return;
                            }
                            catch (Exception ex)
                            {
                                $"{machineInfoTypes.ToString()} 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                            }
                        }
                        break;
                    }
                case MachineInfoTypes.拆盘机:
                    {
                        var entityData = data as DismantlingDiscData;
                        for (int i = 0; i < 3; i++)
                        {
                            try
                            {
                                Battery_DismantlingDiscData.Insert(0, entityData);
                                if (Battery_DismantlingDiscData.Count > 400)
                                {
                                    Battery_DismantlingDiscData.RemoveAt(399);
                                }
                                return;
                            }
                            catch (Exception ex)
                            {
                                $"{machineInfoTypes.ToString()} 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                            }
                        }
                        break;
                    }
                case MachineInfoTypes.盖帽焊:
                    {
                        var entityData = data as CapWeldingData;
                        for (int i = 0; i < 3; i++)
                        {
                            try
                            {
                                Battery_CapWeldingData.Insert(0, entityData);
                                if (Battery_CapWeldingData.Count > 400)
                                {
                                    Battery_CapWeldingData.RemoveAt(399);
                                }
                                return;
                            }
                            catch (Exception ex)
                            {
                                $"{machineInfoTypes.ToString()} 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                            }
                        }
                        break;
                    }
                case MachineInfoTypes.封口机:
                    {
                        var entityData = data as SealingMachineData;
                        for (int i = 0; i < 3; i++)
                        {
                            try
                            {
                                Battery_SealingMachineData.Insert(0, entityData);
                                if (Battery_SealingMachineData.Count > 400)
                                {
                                    Battery_SealingMachineData.RemoveAt(399);
                                }
                                return;
                            }
                            catch (Exception ex)
                            {
                                $"{machineInfoTypes.ToString()} 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                            }
                        }
                        break;
                    }
                case MachineInfoTypes.预充装盘:
                    {
                        var entityData = data as Plate;
                        for (int i = 0; i < 3; i++)
                        {
                            try
                            {
                                Battery_PlateData.Insert(0, entityData);
                                if (Battery_PlateData.Count > 400)
                                {
                                    Battery_PlateData.RemoveAt(399);
                                }
                                return;
                            }
                            catch (Exception ex)
                            {
                                $"{machineInfoTypes.ToString()} 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                            }
                        }
                        break;
                    }
                case MachineInfoTypes.清洗机:
                    {
                        var entityData = data as CleaningData;
                        for (int i = 0; i < 3; i++)
                        {
                            try
                            {
                                Battery_CleaningData.Insert(0, entityData);
                                if (Battery_CleaningData.Count > 400)
                                {
                                    Battery_CleaningData.RemoveAt(399);
                                }
                                return;
                            }
                            catch (Exception ex)
                            {
                                $"{machineInfoTypes.ToString()} 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                            }
                        }
                        break;
                    }
                case MachineInfoTypes.套膜机:
                    {
                        var entityData = data as MantleData;
                        for (int i = 0; i < 3; i++)
                        {
                            try
                            {
                                Battery_MantleData.Insert(0, entityData);
                                if (Battery_MantleData.Count > 400)
                                {
                                    Battery_MantleData.RemoveAt(399);
                                }
                                return;
                            }
                            catch (Exception ex)
                            {
                                $"{machineInfoTypes.ToString()} 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                            }
                        }
                        break;
                    }
                case MachineInfoTypes.喷码机:
                    {
                        var entityData = data as MarkingData;
                        for (int i = 0; i < 3; i++)
                        {
                            try
                            {
                                Battery_MarkingData.Insert(0, entityData);
                                if (Battery_MarkingData.Count > 400)
                                {
                                    Battery_MarkingData.RemoveAt(399);
                                }
                                return;
                            }
                            catch (Exception ex)
                            {
                                $"{machineInfoTypes.ToString()} 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                            }
                        }
                        break;
                    }
            }
        }

        /// <summary>
        /// 界面信息输出
        /// </summary>
        /// <param name="data"></param>
        /// <param name="machineInfoTypes"></param>
        public void AddBattery(object data, MachineInfoTypes machineInfoTypes)
        {
            switch (machineInfoTypes)
            {
                case MachineInfoTypes.换套杯:
                    AddBattery(data as CupSleeveChangingData, Battery_CupSleeveChangingData, machineInfoTypes);
                    break;
                case MachineInfoTypes.折极耳:
                    AddBattery(data as PoleEarFoldingData, Battery_PoleEarFoldingData, machineInfoTypes);
                    break;
                case MachineInfoTypes.入壳机:
                    {
                        AddBattery(data as ShellInsertionData, Battery_ShellInsertionData, machineInfoTypes);
                        break;
                    }
                case MachineInfoTypes.点底焊:
                    {
                        AddBattery(data as SpotoWeldData, Battery_SpotoWeldData, machineInfoTypes);
                        break;
                    }
                case MachineInfoTypes.辊槽机:
                    {
                        AddBattery(data as GrooveRollingMachineData, Battery_GrooveRollingMachineData, machineInfoTypes);
                        break;
                    }
                case MachineInfoTypes.短路测试仪:
                    {
                        AddBattery(data as ShortCircuitTesterData, Battery_ShortCircuitTesterData, machineInfoTypes);
                        break;
                    }   
                case MachineInfoTypes.装盘机:
                    {
                        AddBattery(data as TrayFillerData, Battery_TrayFillerData, machineInfoTypes);
                        break;
                    }
                case MachineInfoTypes.拆盘机:
                    {
                        AddBattery(data as DismantlingDiscData, Battery_DismantlingDiscData, machineInfoTypes);
                        break;
                    }
                case MachineInfoTypes.盖帽焊:
                    {
                        AddBattery(data as CapWeldingData, Battery_CapWeldingData, machineInfoTypes);
                        break;
                    }
                case MachineInfoTypes.封口机:
                    {
                        AddBattery(data as SealingMachineData, Battery_SealingMachineData, machineInfoTypes);
                        break;
                    }
                     
                case MachineInfoTypes.清洗机:
                    {
                        AddBattery(data as CleaningData, Battery_CleaningData, machineInfoTypes);
                        break;
                    }
                     
                case MachineInfoTypes.套膜机:
                    {
                        AddBattery(data as MantleData, Battery_MantleData, machineInfoTypes);
                        break;
                    }
                case MachineInfoTypes.喷码机:
                    {
                        AddBattery(data as MarkingData, Battery_MarkingData, machineInfoTypes);
                        break;
                    }
                case MachineInfoTypes.预充装盘:
                    {
                        AddBattery(data as Plate, Battery_PlateData, machineInfoTypes);
                        break;
                    }
            }
        }
        public void AddBattery<T>(T data, IList<T> batteryData, MachineInfoTypes machineInfoTypes)
        {
            for (int i = 0; i < 3; i++)
            {
                try
                {
                    batteryData.Insert(0, data);
                    if (batteryData.Count > 400)
                    {
                        batteryData.RemoveAt(399);
                    }
                    return;
                }
                catch (Exception ex)
                {
                    $"{machineInfoTypes.ToString()} 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                }
            }
        }

        /// <summary>
        /// 前称重信息输出
        /// </summary>
        /// <param name="barcode">条码</param>
        /// <param name="message">结果</param>
        /// <param name="dateTime">时间</param>
        /// <param name="production">实体</param>
        public void AddBeforeWeighingBattery(string barcode, ResultTypes message, DateTime dateTime, double weighing, int location, Kinlo.Entitys.ProductionData production)
        {
            for (int i = 0; i < 3; i++)
            {
                try
                {
                    Battery_BeforeWeighing.Insert(0, new MessageBeforeWeighingModel()
                    {
                        BarCode = barcode,
                        Result = message,
                        Time = dateTime.ToString("yyyy/MM/dd HH:mm:ss"),
                        FormerWeighing = weighing,
                        LocationFormerWeighing = location,
                        RangeForeweigh = production?.RangeForeweigh ?? string.Empty,
                        TargetInjectionVolume = production?.TargetInjectionVolume ?? 0,
                        NetWeight = production?.NetWeight ?? 0,
                        OneAfterWeighing = production?.OneAfterWeighing ?? 0,
                    });
                    if (Battery_BeforeWeighing.Count > 400)
                    {
                        Battery_BeforeWeighing.RemoveAt(399);
                    }
                    return;
                }
                catch (Exception ex)
                {
                    $"前称重 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                }
            }
        }

        private Action<Kinlo.Entitys.ProductionData, Kinlo.Entitys.ProductionData> _batteryInjectionUpdate;
        /// <summary>
        /// 注液后工序图表
        /// </summary>
        /// <param name="production"></param>
        public void AddOutBattery(Kinlo.Entitys.ProductionData production)
        {
            var model = Battery_AfterFluidInjection.FirstOrDefault(x => x.SnowflakeId == production.SnowflakeId);
            if (_batteryInjectionUpdate == null)
            {
                _batteryInjectionUpdate = ConversionHelper.CopyXCodeEntity<Kinlo.Entitys.ProductionData, Kinlo.Entitys.ProductionData>();
            }
            if (model != null)
            {
                _batteryInjectionUpdate.Invoke(production, model);
                return;
            }
            for (int i = 0; i < 3; i++)
            {
                try
                {
                    Battery_AfterFluidInjection.Insert(0, production);
                    if (Battery_AfterFluidInjection.Count > 400)
                    {
                        Battery_AfterFluidInjection.RemoveAt(399);
                    }
                    return;
                }
                catch (Exception ex)
                {
                    $"注液后 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                }
            }
        }

        /// <summary>
        /// 短路测试仪
        /// </summary>
        /// <param name="barcode">条码</param>
        /// <param name="message">信息</param>
        /// <param name="dateTime">时间</param>
        /// <param name="production">实体</param>
        public void AddShortCircuitBattery(string barcode, Kinlo.Entitys.ProductionData production)
        {
            var model = Battery_ShortCircuit.FirstOrDefault(x => x.SnowflakeId == production.SnowflakeId);
            if (model != null)
            {
                //model.ResistanceTestTime = production.TimeHousing.ToString("yyyy/MM/dd HH:mm:ss");
                //model.ResistanceTestValue = production.ResistanceTestValue;
                return;
            }
            for (int i = 0; i < 3; i++)
            {
                try
                {
                    Battery_ShortCircuit.Insert(0, new MessageShortCircuitModel()
                    {
                        BarCode = barcode,
                        Location = production.LocationShortCircuitTester,
                        SnowflakeId = production.SnowflakeId,
                        Result = production.ResultShortCicute,
                        ElectrodesTestValue = production.ResistanceTestValue,
                        ElectrodesCapacitance = production.ShellShortCicuteCapacitance,
                        ElectrodesTestTime = production.TimeElectrodes.GetDateTime().ToString("yyyy/MM/dd HH:mm:ss"),
                        VP电压 = production.ShellShortCicuteVoltage,
                        跌落1 = production.FallOne,
                        跌落2 = production.FallTwo,
                        跌落3 = production.FallThree,
                        升压时间 = production.BoostTime,
                        开路结果 = production.ShellShortCicuteOpenCircuitResult,
                        放电1结果 = production.ShellShortCicuteDischargeOneResult,
                        放电2结果 = production.ShellShortCicuteDischargeTwoResult,
                        VP结果 = production.ShellShortCicuteVoltageResult,
                        跌落1结果 = production.ShellShortCicuteFallOneResult,
                        跌落2结果 = production.ShellShortCicuteFallTwoResult,
                        跌落3结果 = production.ShellShortCicuteFallThreeResult,
                        TL结果 = production.ShellShortCicuteTLResult,
                        TH结果 = production.ShellShortCicuteTHResult,
                        电阻测试结果 = production.ShellShortCicuteResistanceTestResult,
                        电容测试结果 = production.ShellShortCicuteCapacitanceResult,

                    });
                    if (Battery_ShortCircuit.Count > 400)
                    {
                        Battery_ShortCircuit.RemoveAt(399);
                    }
                    return;
                }
                catch (Exception ex)
                {
                    $"短路测试 第 [{i}] 次 插入日志异常：{ex.ToString().Trim()}".RunLog(MessageLevelType.错误);
                }
            }
        }
    }
}
